package meihua.stopcarapp.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.OnClick;
import meihua.mylibrary.base.BaseActivity;
import meihua.stopcarapp.R;
import meihua.stopcarapp.app.UserConfig;
import meihua.stopcarapp.bean.result.OrderEcodeResult;
import meihua.stopcarapp.model.OrderEcodeModel;
import meihua.stopcarapp.presenter.OrderEcodePresenter;
import meihua.stopcarapp.presenter.contract.OrderEcodeContract;

/**
 * Name: LGZ
 * Time: 2017/5/19.
 * Dec:
 */

public class OrderEcodeActivity extends BaseActivity<OrderEcodePresenter,OrderEcodeModel> implements OrderEcodeContract.View {

    @Bind(R.id.toolbar_center)
    TextView toolbarCenter;
    @Bind(R.id.activity_order_ecode_money)
    TextView activityOrderEcodeMoney;
    @Bind(R.id.activity_order_ecode_btn)
    Button activityOrderEcodeBtn;
    @Bind(R.id.activity_order_ecode_progressbar)
    ProgressBar progressBar;

    String money;

    /**
     * 入口
     *
     * @param activity
     */
    public static void startAction(Activity activity, Bundle bundle) {
        Intent intent = new Intent(activity, OrderEcodeActivity.class);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_ecode;
    }

    @Override
    public void initPresenter() {
        mPresenter.setVM(this,mModel);
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        toolbarCenter.setText("缴纳收费");
        Bundle bundle = getIntent().getExtras();
        money = bundle.getString("order_monry");
        activityOrderEcodeMoney.setText("收费："+money+"元");
    }

    @OnClick({R.id.activity_order_ecode_use, R.id.activity_order_ecode_btn, R.id.toolbar_left})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_order_ecode_use:
                break;
            case R.id.activity_order_ecode_btn:
                mPresenter.secdOrderEcodeRequest(UserConfig.USER_ENTITY.getPark_list_info().getOrder_num(),
                        money,"","");
                break;
            case R.id.toolbar_left:
                this.finish();
                break;
        }
    }


    @Override
    public void showLoading(String title) {
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void stopLoading() {
        progressBar.setVisibility(View.GONE);
    }

    @Override
    public void showErrorTip(String msg) {
        progressBar.setVisibility(View.GONE);
    }

    @Override
    public void returnOrderEcode(OrderEcodeResult result) {
        OrderEcodeFinishActivity.startAction(OrderEcodeActivity.this);
        this.finish();
    }
}
